import 'package:get_it/get_it.dart';
import 'package:mobile_app.core/google_apple_store_purchases/domain/helpers/add_spaces_to_price/helper.dart';
import 'package:mobile_app.core/google_apple_store_purchases/domain/helpers/get_google_apple_store_api_purchase_item_prettified_monthly_price/helper.dart';
import 'package:mobile_app.core/google_apple_store_purchases/domain/helpers/prettify_google_apple_store_api_purchase_item_prices/helper.dart';
import 'package:mobile_app.core/google_apple_store_purchases/domain/use_cases/get_google_apple_store_purchase_item_models/use_case.dart';
import 'package:mobile_app.core/google_apple_store_purchases/domain/use_cases/handle_store_api_purchase_error/use_case.dart';
import 'package:mobile_app.core/google_apple_store_purchases/domain/use_cases/handle_store_api_purchased_item_update/use_case.dart';
import 'package:mobile_app.core/google_apple_store_purchases/domain/use_cases/initialize/use_case.dart';
import 'package:mobile_app.core/google_apple_store_purchases/domain/use_cases/request_store_api_purchase/use_case.dart';
import 'package:mobile_app.core/injection_container.dart' as core_di;

final sl = GetIt.asNewInstance();

Future<void> init() async {
  // domain helpers

  sl.registerLazySingleton<AddSpacesToPrice>(() {
    return const AddSpacesToPriceImpl();
  });

  sl.registerLazySingleton<GetGoogleAppleStoreApiPurchaseItemPrettifiedMonthlyPrice>(() {
    return GetGoogleAppleStoreApiPurchaseItemPrettifiedMonthlyPriceImpl(
      addSpacesToPrice: sl(),
    );
  });

  sl.registerLazySingleton<PrettifyGoogleAppleStoreApiPurchaseItemPrices>(() {
    return PrettifyGoogleAppleStoreApiPurchaseItemPricesImpl(
      addSpacesToPrice: sl(),
    );
  });

  // use cases

  sl.registerLazySingleton<GetGoogleAppleStorePurchaseItemModels>(() {
    return GetGoogleAppleStorePurchaseItemModelsImpl(
      googleAppleStoreApiService: core_di.sl(),
      getStoreApiPurchaseItemPrettifiedMonthlyPrice: sl(),
      prettifyStoreApiPurchaseItemPrices: sl(),
    );
  });

  sl.registerLazySingleton<HandleStoreApiPurchaseError>(() {
    return HandleStoreApiPurchaseErrorImpl(
      analyticsService: core_di.sl(),
    );
  });

  sl.registerLazySingleton<HandleStoreApiPurchasedItemUpdate>(() {
    return HandleStoreApiPurchasedItemUpdateImpl(
      googleAppleStoreApiService: core_di.sl(),
      getPremiumAccessInfoFromPurchasedItems: core_di.sl(),
      purchasedItemApiRepository: core_di.sl(),
      createPremiumAccessStatus: core_di.sl(),
      userSecureRepository: core_di.sl(),
      analyticsService: core_di.sl(),
      handleAccessCredentialUpdate: core_di.sl(),
      userRepository: core_di.sl(),
    );
  });

  sl.registerLazySingleton<Initialize>(() {
    return InitializeImpl(
      googleAppleStoreApiService: core_di.sl(),
    );
  });

  sl.registerLazySingleton<RequestStoreApiPurchase>(() {
    return RequestStoreApiPurchaseImpl(
      analyticsService: core_di.sl(),
      googleAppleStoreApiService: core_di.sl(),
    );
  });
}
